package com.fresh.auth.controller;


import com.fresh.auth.Service.PermissionService;
import com.fresh.common.ResponseResult;
import com.fresh.entity.Permission;
import com.fresh.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    PermissionService permissionService;

    @PostMapping("/getAll")
    public Object getAll(@RequestBody User user){
        List<Permission> permissions = permissionService.getPermissions(user.getUserId());
        return new ResponseResult(200,"ok",permissions);
    }

    @GetMapping("/all")
    public ResponseResult all(){
        List<Permission> list = permissionService.getAll();
        return new ResponseResult(200,"ok",list);
    }

    @PostMapping("/add")
    public Object add(@RequestBody Permission permission){
        permissionService.add(permission);
        return new ResponseResult(200,"ok",null);
    }

}
